package com.key.handler;

import java.util.List;

import android.os.PowerManager.WakeLock;

import com.key.model.RecordModel;
import com.key.util.Contants;

public class Utils {
	public static	WakeLock wakeLock;
	
	public static boolean resolveSetting(String line, List<RecordModel> list) {
		try {
			String[] str = line.split("[)]");
			if (str.length > 1) {
				String callPrefixs = str[0].substring(1);
				RecordModel model = new RecordModel();
				if (!callPrefixs.equals("")) {
					String[] callPrefixStrs = callPrefixs.split("[,]");
					for (int i = 0; i < callPrefixStrs.length; i++) {
						model.callPrefix.add(callPrefixStrs[i]);
					}
				}
				model.timeLength = str[1];
				list.add(model);
			}
		} catch (Exception e) {
			//Contants.writeFileToSD("[1004]" + e.toString());
			return false;
		}
		return true;
	}

	public static String isRecordingCall(List<RecordModel> list,
			String phoneNumber) {
		String flag = "-1";
		if (list == null || list.size() <= 0) {
			return "-1";
		} else {
			for (int i = 0; i < list.size(); i++) {
				RecordModel recordModel = list.get(i);
				if (recordModel.callPrefix.size() <= 0 && flag.equals("-1")) {
					flag = recordModel.timeLength;
				}
				boolean isRecord = false;
				for (int j = 0; j < recordModel.callPrefix.size(); j++) {
					String prefix = recordModel.callPrefix.get(j);
					if (phoneNumber.startsWith(prefix)) {
						isRecord = true;
						break;
					}
				}
				if (isRecord) {
					flag = recordModel.timeLength;
				}
			}
		}

		return flag;
	}
}
